// 2025/5/20
// dd爱旋转

#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
    int n, q, x = 0, tmp;
    cin >> n;
    vector<vector<int>> matrix(n, vector<int>(n));
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            cin >> matrix[i][j];
        }
    }

    cin >> q;
    while(q--)
    {
        cin >> tmp;
        x ^= tmp;
    }
    if(x & 1)
    {
        reverse(matrix.begin(), matrix.end());
        for(auto& row : matrix)
            reverse(row.begin(), row.end());
    }
    if(x & 2)
    {
        reverse(matrix.begin(), matrix.end());
    }
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            cout << matrix[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}
// 64 位输出请用 printf("%lld")